﻿using CodeNotes.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcCodeNotes.Controllers
{
    public class ValidateCodeController : Controller
    {
        //
        // GET: /ValidateCode/

        public ActionResult Index()
        {
            return View();
        }

        //2.2图片流以图片的形式响应到页面

        public ActionResult GetImg()
        {
            int width = 100;
            int height = 40;
            int fontsize = 20;
            string code = string.Empty;
            byte[] bytes = ValidateCode.CreateValidateGraphic(out code, 4, width, height, fontsize);

            return File(bytes, @"image/jpeg");
        }

        public ActionResult GetImgByTxt(string txt)
        {
            int width = 220;
            int height = 150;
            int fontsize = 30;
            string code = string.Empty;
            byte[] bytes = ValidateCode.CreateFontGraphic(txt, width, height, fontsize);

            return File(bytes, @"image/jpeg");
        }

        public ActionResult GetAutoImgByTxt(string txt)
        {
            if (string.IsNullOrEmpty(txt))
                return null;
            int fontsize = 20;
            string code = string.Empty;
            byte[] bytes = ValidateCode.CreateFontGraphic(txt, fontsize);

            return File(bytes, @"image/jpeg");
        }
    }
}
